package cn.test.house.services.impl;

import cn.test.house.beans.User;
import cn.test.house.beans.UserExample;
import cn.test.house.daos.UserMapper;
import cn.test.house.services.UserService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;



    @Override
    public List<User> getUsers() {
        return userMapper.selectByExample(new UserExample());
    }

    @Override
    public User getUserById(int id) {
        return userMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<User> getUserByNameAndSex(User user) {
        //设置条件
//        UserExample userExample=new UserExample();
//        UserExample.Criteria criteria = userExample.createCriteria();
//        criteria.andNameEqualTo(name);
////        criteria.andSexEqualTo(sex);


        List<User> users = userMapper.selectByVague(user);
        return users;
    }


    @Override
    public List<User> getUsersByPage(int nowPage, int pageSize) {
        PageHelper.startPage(nowPage,pageSize);
        List<User> users = userMapper.selectByExample(new UserExample());
        return users;
    }

    @Override
    public Integer addUser(User user) {
        return userMapper.insert(user);
    }

    @Override
    public Integer delAllUser(List arryId) {
        return userMapper.deleteAll(arryId);
    }


    @Override
    public Integer deleteUserById(int id) {
        return userMapper.deleteByPrimaryKey(id);
    }
}
